export function padZeroes(key: any) {
    const no0x = key.replace("0x", "");
    return "0".repeat(64 - no0x.length) + no0x;
}

export function numberToKey(slot: any) {
    let hexSlot = slot.toString(16);
    if (hexSlot.length % 2 === 1) hexSlot = "0" + hexSlot;
    return padZeroes(hexSlot);
}

export function addBuffers(a: any, b: any) {
    const BYTES = 32;
    const WORDS = BYTES / 2;
    const WORD_LENGTH = 16;
    const WORD_MASK = 0xffff;

    const mem = new Uint32Array(2);
    const lv = new Uint16Array(a);
    const rv = new Uint16Array(b);
    for (let i = 0; i < WORDS; i += 1) {
        mem[0] = mem[1] + lv[i] + rv[i];
        lv[i] = mem[0] & WORD_MASK;
        mem[1] = mem[0] >>> WORD_LENGTH;
    }
    return Buffer.from(lv);
}
